#ifndef REMOTEAPI_H
#define REMOTEAPI_H

#include <Arduino.h>
#include <WiFi.h>
#include <HTTPClient.h>

const char* remote_ip = "192.168.1.121";
int remote_port = 80;

void send_request(const String& endpoint) {
    HTTPClient http;
    http.setTimeout(100);
    String url = "http://" + String(remote_ip) + ":" + String(remote_port) + "/" + endpoint;
    http.begin(url);
    int httpResponseCode = http.GET();
    if (httpResponseCode == 200) {
        Serial.println("[XTouch][API]成功触发 " + endpoint + ": " + http.getString());
    } else {
        Serial.println("[XTouch][API]触发 " + endpoint + " 失败: " + String(httpResponseCode));
    }
    http.end();
}

void set_remote_speed(short speed) {
    send_request("setSpeed?value=" + String(speed));
}

void start_motor() {
    send_request("start");
}

void stop_motor() {
    send_request("stop");
}

void toggle_light() {
    send_request("toggleLight");
}

#endif // REMOTEAPI_H